package cn.yuan.xiaoyu.testmodule.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Region;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Scroller;

/**
 * Created by yukuoyuan on 2017/4/13.
 */

public class TestView extends View {

    private Scroller scroller;
    private Paint paint;
    private Paint paint1;

    public TestView(Context context) {
        super(context);
    }

    public TestView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    private void initPaint() {
        /**
         * 初始化两个画笔
         */
        paint = new Paint();
        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.FILL);

        paint1 = new Paint();
        paint1.setColor(Color.BLUE);
        paint1.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        /**
         * 绘制两个矩形
         */
        canvas.drawRect(200, 500, 900, 1500, paint);
        RectF rectF = new RectF(200, 500, 900, 1500);
        canvas.clipRect(rectF, Region.Op.XOR);
        RectF rects = new RectF(100, 200, 400, 700);
        canvas.clipRect(rects, Region.Op.XOR);
        canvas.drawRect(100, 200, 400, 700, paint1);
    }
}
